using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

public abstract class ICamp
{
    // 兵营本身信息
    protected GameObject mGameObject;
    protected string mName;
    protected string mIconSprite;
    protected SoldierType mSoldierType; // 兵营所生产的战士类型
    // 训练完成后,士兵集合的点 (//? 训练?)
    protected Vector3 mPosition;
    // 训练时间
    private float mTrainTime;
    private float mTrainTimer = 0;

    // 命令管理
    protected List<ITrainCommand> mCommands;
    // 需要消耗的能量(策略中获取)
    protected IEnergyCostStrategy energyCostStrategy;
    protected int mEnergyCostCampUpgrade;//兵营升级
    protected int mEnergyCostWeaponUpgrade;//武器升级
    protected int mEnergyCostTrain;//训练士兵

    public ICamp(GameObject gameObject, string name, string icon, SoldierType soldierType, Vector3 position,float trainTime)
    {
        mGameObject = gameObject;
        mName = name;
        mIconSprite = icon;
        mSoldierType = soldierType;
        mPosition = position;
        mTrainTime = trainTime;
        mTrainTimer = mTrainTime;
        mCommands = new List<ITrainCommand>();
    }

    public virtual void Update() {
        UpdateCommand();
    }
    // 更新命令状态
    private void UpdateCommand()
    {
        if (mCommands.Count <= 0) return;
        mTrainTimer -= Time.deltaTime;
        // 训练时间跟训练士兵类型有关
        if (mTrainTimer <= 0)
        {
            mCommands[0].Execute();
            mCommands.RemoveAt(0);
            mTrainTimer = mTrainTime;
        }
    }
    public abstract WeaponType weaponType { get; }
    public abstract int lv { get; }
    public string name { get { return mName; } }
    public string iconSprite { get { return mIconSprite; } }
    public abstract int energyCostCampUpgrade { get; }
    public abstract int energyCostWeaponUpgrade { get; }
    public abstract int energyCostTrain { get; }
    
    // 命令管理-训练命令
    public abstract void Train();

    public void CancelTrainCommand()
    {
        if (mCommands.Count > 0)
        {
            // 移除最后一个命令
            mCommands.RemoveAt(mCommands.Count - 1);
            // 重置训练时间
            if (mCommands.Count == 0)
            {
                mTrainTimer = mTrainTime;
            }
        }
    }

    public int trainCount{get {return mCommands.Count;}}    
    public float trainRemainingTime{get{return mTrainTimer;}}

    protected abstract void UpdateEnergyCost();
    public abstract void UpgradeCamp();
    public abstract void UpgradeWeapon();
}